const { exec } = require('child_process')
const sleep = require('thread-sleep')
const axios = require('axios')
const { host } = require('./src/config')

const DELAY = 500

axios.post(`${host}/web.do?fn=qryASIN`).then(({ data }) => {
    const asins = data.data.map(item => item.asin)
    asins.forEach(asin => {
        exec(`open http://www.amazon.com/dp/${asin}`)
        // 3 ~ 8 seconds
        const randomSeconds = parseInt(Math.random() * 5 + 3)
        console.log(`sleep ${randomSeconds} seconds`)
        sleep(randomSeconds * DELAY)
    })
})
